/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tp4_poo;

/**
 *
 * @author alexander
 */
public class Arreglo {

    private int[] vectorr = {5, 2, 9, 1, 7};
//constructor

    public Arreglo() {
    }

    public Arreglo(int vectorr[]) {
        this.vectorr = vectorr;
    }

//metodos
    public int[] getArreglo() {
        return this.vectorr;
    }

//    public void setArreglo(int num) {
//        for (int i = 0; i < vectorr.length; i++) {
//            this.vectorr[i] = num;
//            num = num +1;
//        }
//    }
    public void cargarUnElementoArreglo(int num, int i) {
        if (this.vectorr[i] == 0) {
            this.vectorr[i] = num;

        } else {
            System.out.print("No se puede cargar, posición ocupada");
        }

    }

    public void mostrarArreglo() {
        for (int i = 0; i < vectorr.length; i++) {
            System.out.println(this.vectorr[i]);
        }
    }

    public void cargarArreglo() {
        int valor = 1;
        for (int i = 0; i < vectorr.length; i++) {
            this.vectorr[i] = valor;
            System.out.println(valor);
            valor += 10;

        }
    }

    public int cantidadElementos() {
        return this.vectorr.length;
    }

    public void eliminarElemento(int elem) /**
     * throws Throwable*
     */
    {
        int i = 0;
        while (i < (this.cantidadElementos() - 1)) {
            if (this.vectorr[i] != elem) {
                i++;
            } else {
                for (; i <= vectorr.length; i++) {
                    if ((i + 1) >= vectorr.length) {
                        vectorr[i] = 0;
                        i++;
                    } else {
                        this.vectorr[i] = this.vectorr[i + 1];
                    }
                }
            }
        }
    }

    public boolean buscarElemento(int elem) {
        boolean existe = false;
        for (int i = 0; i < this.vectorr.length; i++) {
            if (this.vectorr[i] == elem) {
                existe = true;
            } else {
                existe = false;
            }
        }
        return existe;
    }

    public int unElementoVector(int e) {
        return this.vectorr[e];
    }

    public void ordenarVector() {
        int aux;
        for (int e = 0; e < (this.vectorr.length - 1); e++) {
            for (int i = 0; i < (this.vectorr.length - 1); i++) {
                if (this.vectorr[i] > this.vectorr[i + 1]) {
                    aux = this.vectorr[i];
                    this.vectorr[i] = this.vectorr[i + 1];
                    this.vectorr[i + 1] = aux;
                }
            }
        }
    }

}
